
#include "MenuFactory.h"
#include "IMenuComponent.h"
#include "MenuItemComp.h"
#include "MenuBackItemComp.h"

#include <sstream>

std::string itos(int i);

IMenuComponent *myMenuFactory::createNewMenu() {
    IMenuComponent *menu = new MenuComp;
    menu->setText("New Game");
    menu->setDesc("Set number of players. default=2");
    int time = 8;
    generate(menu, time);
    addBackMenuto(menu);
    return menu;
}

IMenuComponent *myMenuFactory::createLoadMenu() {
    IMenuComponent *menu = new MenuComp;
    menu->setText("Load Game");
    menu->setDesc("Select the Record to be loaded(1-5)");
    int time = 5;
    generate(menu, time);
    addBackMenuto(menu);
    return menu;
}

IMenuComponent *myMenuFactory::createSaveMenu() {
    IMenuComponent *menu = new MenuComp;
    menu->setText("Save Game");
    menu->setDesc("Select the Record to save(1-5)");
    int time = 5;
    generate(menu, time);
    addBackMenuto(menu);
    return menu;
}
IMenuComponent *myMenuFactory::createOptionMenu() {
    IMenuComponent *menu = new MenuComp;
    menu->setText("Options");
    menu->setDesc("Set options for game");
        IMenuComponent *subMenu = new MenuComp;
        subMenu->setText("Set the value of Volume(0-100)");
        subMenu->setDesc("Set Volume");

            //subsubMenu
            IMenuComponent *volumSubItem=new MenuItemComp;
            volumSubItem->setText("input value(0-100)");
            volumSubItem->setDesc("Set Volume");

        subMenu->add(volumSubItem);
        addBackMenuto(subMenu);
    menu->add(subMenu);

    subMenu = new MenuComp;
    subMenu->setText("Set the resoultion");
    subMenu->setDesc("Set resolution");
    //subsubMenu
        IMenuComponent *resoultionItem = new MenuItemComp;
        resoultionItem->setText("640X320");
        subMenu->add(resoultionItem);

        resoultionItem = new MenuItemComp;
        resoultionItem->setText("800X600");
        subMenu->add(resoultionItem);

        resoultionItem = new MenuItemComp;
        resoultionItem->setText("1024X768");
        subMenu->add(resoultionItem);

    addBackMenuto(subMenu);

    menu->add(subMenu);
    addBackMenuto(menu);
    return menu;
}

void myMenuFactory::addBackMenuto(IMenuComponent *menu) const {
    IMenuComponent *
            subMenu = new MenuBackItemComp;
    subMenu->setText("Back");
    menu->add(subMenu);
}

IMenuComponent *myMenuFactory::createPlayMenu() {
    IMenuComponent *menu = new MenuItemComp;
    menu->setText("Play");
    addBackMenuto(menu);
    return menu;
}

IMenuComponent *myMenuFactory::createExitMenu() {
    IMenuComponent *menu = new MenuItemComp;
    menu->setText("Exit");
    addBackMenuto(menu);
    return menu;
}

void myMenuFactory::generate(IMenuComponent *pComponent, int time) {
    for (int i = 0; i != time; ++i) {
        IMenuComponent *sub = new MenuItemComp;
        sub->setText(itos(i));
        pComponent->add(sub);
    }

}

std::string itos(int i) {
    std::stringstream ss;
    ss << i;
    return ss.str();
}

